Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reach/dialog

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/dialog

Accessible React Modal Dialog.

  • 0.2.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
139K
decreased by-21.35%
Maintainers
1
Weekly downloads
 
Created

What is @reach/dialog?

@reach/dialog is a React component library that provides accessible modal dialogs. It ensures that dialogs are properly announced to screen readers and that focus is managed correctly, making it easier to build accessible web applications.

What are @reach/dialog's main functionalities?

Basic Dialog

This code demonstrates a basic usage of the @reach/dialog package. It shows how to open and close a dialog with a button click.

import { Dialog } from '@reach/dialog';
import '@reach/dialog/styles.css';

function BasicDialogExample() {
  const [showDialog, setShowDialog] = React.useState(false);
  return (
    <div>
      <button onClick={() => setShowDialog(true)}>Open Dialog</button>
      {showDialog && (
        <Dialog onDismiss={() => setShowDialog(false)}>
          <p>This is a basic dialog.</p>
          <button onClick={() => setShowDialog(false)}>Close</button>
        </Dialog>
      )}
    </div>
  );
}

Dialog with Custom Styling

This example shows how to apply custom styles to the dialog component.

import { Dialog } from '@reach/dialog';
import '@reach/dialog/styles.css';

function CustomStyledDialog() {
  const [showDialog, setShowDialog] = React.useState(false);
  return (
    <div>
      <button onClick={() => setShowDialog(true)}>Open Custom Dialog</button>
      {showDialog && (
        <Dialog
          onDismiss={() => setShowDialog(false)}
          style={{ background: 'lightblue', padding: '20px' }}
        >
          <p>This is a custom styled dialog.</p>
          <button onClick={() => setShowDialog(false)}>Close</button>
        </Dialog>
      )}
    </div>
  );
}

Dialog with Focus Management

This example demonstrates how to manage focus within the dialog, ensuring accessibility for keyboard and screen reader users.

import { Dialog } from '@reach/dialog';
import '@reach/dialog/styles.css';

function FocusManagedDialog() {
  const [showDialog, setShowDialog] = React.useState(false);
  return (
    <div>
      <button onClick={() => setShowDialog(true)}>Open Focus Managed Dialog</button>
      {showDialog && (
        <Dialog
          onDismiss={() => setShowDialog(false)}
          initialFocusRef={React.useRef(null)}
        >
          <p>This dialog manages focus correctly.</p>
          <button onClick={() => setShowDialog(false)}>Close</button>
        </Dialog>
      )}
    </div>
  );
}

Other packages similar to @reach/dialog

FAQs

Package last updated on 06 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc